/*********** MessageBox ****************/
// simply show info.  Only close button
function infoMessageBox(message, title){
	$("#info-body").html(message);
	$("#info-title").html(title);
	$("#info-popup").modal('show');
}
// modal with full control
function messageBox(body, title, ok_text, close_text, callback){
	$("#modal-body").html(body);
	$("#modal-title").html(title);
	if (ok_text) $("#modal-button").html(ok_text);
	if(close_text) $("#modal-close-button").html(close_text);
	$("#modal-button").unbind("click"); // remove existing events attached to this
	$("#modal-button").click(callback);
	$("#popup").modal("show");
}


/*********** crontab actions ****************/

function editJob(name,_id, kwargs){

	var kwargs = JSON.parse(kwargs)
	$("#job").modal("show");
	$("#job-command").val(job.command);
	if(name=='INTERVAL'){
		$('#job-minute').val(kwargs.minute)
		$('#job-hour').attr('disabled', 'true');
		$('#job-day').attr('disabled', 'true');
		$('#job-limit').attr('disabled', 'true');
		$('#job-exceed').attr('disabled', 'true');
		$('#job-hour').val("*");
		$('#job-day').val("*");
		$('#job-limit').val("*");
		$('#job-exceed').val("*");
		
	}else{
		$('#job-hour').removeAttr('disabled');
		$('#job-day').removeAttr('disabled');
		$('#job-limit').removeAttr('disabled');
		$('#job-exceed').removeAttr('disabled');
		$('#job-minute').val(kwargs.minute)
		$('#job-hour').val(kwargs.hour);
		$('#job-day').val(kwargs.interval_day);
		$('#job-limit').val(kwargs.limit_day);
		$('#job-exceed').val(kwargs.exceed_day);
	}
	// if macro not used

	$("#job-save").unbind("click"); // remove existing events attached to this
	$("#job-save").click(function(){
		// TODO good old boring validations
		schedule = $("#job-minute").val() + " " +$("#job-hour").val() + " " + $("#job-day").val() + " " +$('#job-limit').val() + " " + $('#job-exceed').val();
		$.post("/Add", {name: name, _id:_id, schedule: schedule}, function(){
			location.reload();
		})
	});
}

